@extends('layout.master')

@section('title','修改文章')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')

    @if (session('message'))
        <div>
            <input type="hidden" id="hidden" name="hidden" value="hidden">
            <input type="hidden" id="message" name="message" value="{{ session('message') }}">
            <input type="hidden" id="status" name="status" value="{{ session('status') }}">
        </div>
    @endif

    <div class="row">
        <form class="col-lg-12 col-md-12" method="post" enctype="multipart/form-data">
            <input type="hidden" name="art_id" value="{{ $tiezi['archive_id'] }}">
            <div class="white-box">
                <div class="row">
                    <div class="col-md-12 col-sm-12">
                        <div class="row">
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="col-md-12">文章标题</label>
                                    <div class="col-md-12">
                                        <input type="text" name="title" value="{{ $tiezi['title'] }}"
                                               class="form-control form-control-line" required>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <label class="control-label">科室</label>
                                <div class="example">
                                    <select style="height: 38px" name="keshi_id">
                                        @foreach (App\Keshi::Keshis() as $value)
                                            <option value="{{ $value->id }}"
                                                    @if($tiezi['keshi_id'] === $value->id) selected @endif >{{ $value->title }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <label class="control-label">话题</label>
                                <div class="example">
                                    <select style="height: 38px" name="huati_id">
                                        <option value="0" @if($tiezi['huati_id'] === 0) selected @endif>无</option>
                                        @foreach (App\Huati::Huatis() as $value)
                                            <option value="{{ $value->id }}"
                                                    @if($tiezi['huati_id'] === $value->id) selected @endif>{{ $value->title }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                        </div>
                        <hr/>
                        <div class="row">
                            <div class="col-md-12 col-sm-12">
                                <textarea style="width: 100%" rows="40" name="contents">{{ $tiezi['content'] }}</textarea>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2">
                                <div class="row">
                                    <label class="control-label">图片/视频</label>
                                </div>
                                <div class="row">
                                    <div class="radio radio-purple">
                                        <input type="radio" name="porm" @if(isset($tiezi['pic'])) checked disabled
                                               @endif id="pic" value="1">
                                        <label for="radio8"> 图片 </label>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="radio radio-purple">
                                        <input type="radio" name="porm" @if(isset($tiezi['video'])) checked disabled
                                               @endif id="video" value="2">
                                        <label for="radio8"> 视频 </label>
                                    </div>
                                </div>
                            </div>
                            <div align="center" class="col-md-10 col-lg-10">
                                @if(isset($tiezi['video']))

                                    <video controls style="width: 80%">
                                        <source src="{{ $tiezi['video'] }}" type="video/mp4">
                                        <source src="{{ $tiezi['video'] }}" type="video/ogg">
                                        <source src="{{ $tiezi['video'] }}" type="video/webm">
                                        <object data="{{ $tiezi['video'] }}">
                                            <embed src="{{ $tiezi['video'] }}">
                                        </object>
                                    </video>

                                    <div class="col-md-3 col-lg-3">
                                        <label class="control-label">如果您想更换视频，请在这里选择新的视频</label>
                                    </div>
                                    <div class="col-lg-4 col-md-4" id="video">
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="video"
                                                   data-height="100px"
                                                   data-default-file=""/>
                                        </div>
                                    </div>
                                @elseif(isset($tiezi['pic']))
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           onclick="picdel({{ $tiezi['pic'][0]['pic_id'] }})">删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic0"
                                                   data-height="100px"
                                                   data-default-file="{{ $tiezi['pic'][0]['path'] }}"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           @if(isset($tiezi['pic'][1]))onclick="picdel({{ $tiezi['pic'][1]['pic_id'] }})"@endif>删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic1"
                                                   data-height="100px"
                                                   data-default-file="@if(isset($tiezi['pic'][1])){{ $tiezi['pic'][1]['path'] }}@endif"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           @if(isset($tiezi['pic'][2]))onclick="picdel({{ $tiezi['pic'][2]['pic_id'] }})"@endif>删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic2"
                                                   data-height="100px"
                                                   data-default-file="@if(isset($tiezi['pic'][2])){{ $tiezi['pic'][2]['path'] }}@endif"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           @if(isset($tiezi['pic'][3]))onclick="picdel({{ $tiezi['pic'][3]['pic_id'] }})"@endif>删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic3"
                                                   data-height="100px"
                                                   data-default-file="@if(isset($tiezi['pic'][3])){{ $tiezi['pic'][3]['path'] }}@endif"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           @if(isset($tiezi['pic'][4]))onclick="picdel({{ $tiezi['pic'][4]['pic_id'] }})"@endif>删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic4"
                                                   data-height="100px"
                                                   data-default-file="@if(isset($tiezi['pic'][4])){{ $tiezi['pic'][4]['path'] }}@endif"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           @if(isset($tiezi['pic'][5]))onclick="picdel({{ $tiezi['pic'][5]['pic_id'] }})"@endif>删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic5"
                                                   data-height="100px"
                                                   data-default-file="@if(isset($tiezi['pic'][5])){{ $tiezi['pic'][5]['path'] }}@endif"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           @if(isset($tiezi['pic'][6]))onclick="picdel({{ $tiezi['pic'][6]['pic_id'] }})"@endif>删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic6"
                                                   data-height="100px"
                                                   data-default-file="@if(isset($tiezi['pic'][6])){{ $tiezi['pic'][6]['path'] }}@endif"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           @if(isset($tiezi['pic'][7]))onclick="picdel({{ $tiezi['pic'][7]['pic_id'] }})"@endif>删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic7"
                                                   data-height="100px"
                                                   data-default-file="@if(isset($tiezi['pic'][7])){{ $tiezi['pic'][7]['path'] }}@endif"/>
                                        </div>
                                    </div>
                                    <div class="col-lg-4 col-md-4">
                                        <a class="fcbtn btn-success btn-outline btn-1e waves-effect"
                                           @if(isset($tiezi['pic'][8]))onclick="picdel({{ $tiezi['pic'][8]['pic_id'] }})"@endif>删除此图</a>
                                        <div class="form-group ">
                                            <input type="file" id="input-file-now-custom-3" class="dropify" name="pic8"
                                                   data-height="100px"
                                                   data-default-file="@if(isset($tiezi['pic'][8])){{ $tiezi['pic'][8]['path'] }}@endif"/>
                                        </div>
                                    </div>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect">确认修改
                    </button>
                    {!! csrf_field() !!}
                </div>
            </div>
        </form>
    </div>
@endsection
@section('js')
    @parent
    <!-- icheck -->
    <script src="{{ asset('plugins/bower_components/icheck/icheck.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/icheck/icheck.init.js') }}"></script>
    <script src="{{ asset('js/jasny-bootstrap.js') }}"></script>
    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/summernote/dist/summernote.min.js') }}"></script>
    <script>
        $(document).ready(function () {
            // Basic
            $('.dropify').dropify();
        });
    </script>
    <script src="{{ asset('plugins/bower_components/bootstrap-select/bootstrap-select.min.js') }}"
            type="text/javascript"></script>
    <!-- bt-switch -->
    <script src="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.js') }}"></script>
    <script type="text/javascript">

        jQuery(document).ready(function () {

            $('.summernote').summernote({
                height: 350, // set editor height
                minHeight: null, // set minimum height of editor
                maxHeight: null, // set maximum height of editor
                focus: false, // set focus to editable area after initializing summernote$('.summernote').summernote({
                toolbar: [
                    // [groupName, [list of button]]
                    // ['style', ['bold', 'italic', 'underline', 'clear']],
                    // ['fontsize', ['fontsize']],
                    // ['fontname', ['fontname']],
                    // ['color', ['color']],
                    // ['para', ['ul', 'ol', 'paragraph']],
                    // ['height', ['height']],
                    // ['insert', ['link', 'picture', 'video']],
                    // ['view', ['fullscreen', 'codeview', 'help']]
                ],
                lang: 'zh-CN',
                // placeholder: '内容',
                dialogsFade: true,
            });

            $('.inline-editor').summernote({
                airMode: true
            });

        });

        $(".bt-switch input[type='checkbox'], .bt-switch input[type='radio']").bootstrapSwitch();
        var radioswitch = function () {
            var bt = function () {
                $(".radio-switch").on("switch-change", function () {
                    $(".radio-switch").bootstrapSwitch("toggleRadioState")
                }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck")
                    }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck", !1)
                    })
            };
            return {
                init: function () {
                    bt()
                }
            }
        }();
        $(document).ready(function () {
            radioswitch.init()
        });


        $(document).ready(function () {
            var hidden = $('#hidden').val();
            if (hidden === 'hidden') {
                if ($('#status').val() == 1) {
                    toastsuccess($('#message').val());
                } else {
                    toasterror($('#message').val());
                }
            }
        });

        function picdel(pic_id) {

            swal({
                    title: "",
                    text: "确定删除该图片吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/post/postPicDel/' + pic_id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {

                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }

    </script>
@endsection